//
//  GMBaseViewController.m
//  gentleman
//
//  Created by 范月成 on 2017/12/5.
//  Copyright © 2017年 fancy. All rights reserved.
//

#import "GMBaseViewController.h"

@interface GMBaseViewController ()

@end

@implementation GMBaseViewController

- (void)dealloc {
    DEBUGLog(@"%@_dealloc", self.class);
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        [self didInitialized];
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    if (self = [super initWithCoder:aDecoder]) {
        [self didInitialized];
    }
    return self;
}

- (void)didInitialized {
    self.extendedLayoutIncludesOpaqueBars = YES;
    self.supportedOrientationMask = UIInterfaceOrientationMaskPortrait;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    if (!self.view.backgroundColor) {
        self.view.backgroundColor = [UIColor whiteColor];
    }
    
    [self initSubviews];
}

#pragma mark - 屏幕旋转

- (BOOL)shouldAutorotate {
    return YES;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return self.supportedOrientationMask;
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return  UIStatusBarStyleLightContent;
}

- (BOOL)preferredNavigationBarHidden {
    return NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    DEBUGLog(@"%@_didReceiveMemoryWarning", self.class);
    [[SDImageCache sharedImageCache] clearMemory];
}

@end

@implementation GMBaseViewController (GMSubclassingHooks)

- (void)initSubviews {
    // 子类重写
}

@end

@implementation GMBaseViewController (GMLayout)

- (CGFloat)safeAreaTop {
    if (self.navigationController) {
        if (kIPhoneX) {
            return 88;
        } else {
            return 64;
        }
    } else {
        if (kIPhoneX) {
            return 44;
        } else {
            return 20;
        }
    }
}

- (CGFloat)safeAreaBottom {
    if (self != self.navigationController.viewControllers.firstObject) {
        if (kIPhoneX) {
            return 34;
        } else {
            return 0;
        }
    } else {
        if (kIPhoneX) {
            return 83;
        } else {
            return 49;
        }
    }
}

@end
